<?php

class Single_truck_exam extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Confirm_sheet':
	 * @var integer $id
	 * @var integer $loading_status
	 * @var double $mileage
	 * @var string $amount_kind
	 * @var double $advance_payment
	 * @var double $balance
	 * @var double $total_amount
	 * @var string $remark
	 * @var double $gas_fee
	 * @var double $bridge_charge
	 * @var string $origin
	 * @var string $destination
	 * @var string $fuel_name
	 * @var double $extra_cost
	 * @var double $total_cost
	 * @var integer $state
	 * @var string $create_time
	 */
	
	
	public $consignor_name;
	public $extra_cost;
	public $loading_place;
	public $pod_place;
	
	public $driver_name;
	
	
	private $_loading_status=array('0'=>'重驶','1'=>'指定空驶');
	private $_return_paper=array('0'=>'是','1'=>'否');

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'confirm_sheet';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
		);
	}
	

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'consignor_name'=>'货主(发货人)',
			'consignee_name'=>'客户(收货人)',
			'origin' =>'始发地',
			'destination'=>'目的地',
			'id' => '索引号',
			'confirm_no' => '派车单号',
			'truck_plate_no' =>'车牌号',
			'driver_name' =>'司机姓名',
			'loading_status' => '行驶状态',//0重驶 1指定空驶
			'total_amount' => '收入总额',
			'remark' => '备注',
			'gas_fee' => '油费',
			'bridge_charge' => '路桥费',
			'amerce_cost'=>'罚款',
			'driver_salary' => '司机绩效',
			'return_paper' => '回单',
			'create_time' => '确认日期',
			'extra_cost' => '其他费用',
			'appointment_time'=>'业务日期'
		);
	}
	
	public function excelAttributes(){//导出excel所需的字段名、列号、宽度
		return array(
			'confirm_no'=>array('B',13),
			'appointment_time'=>array('C',13),
			'create_time'=>array('D',13),
			'loading_status'=>array('E',12,'getLoadingStatusName'),
			'truck_plate_no'=>array('F',12),
			'driver_name'=>array('G',15),
			'consignor_name'=>array('H',17),
			'origin' =>array('I',15),
			'destination'=>array('J',15),
			'total_amount' => array('K',12,'sum'=>true),
			'return_paper' => array('L',5,'getReturnPaperName'),
			'driver_salary' => array('M',12,'sum'=>true),
			'gas_fee' => array('N',12,'sum'=>true),
			'bridge_charge' => array('O',12,'sum'=>true),
			'amerce_cost'=>array('P',12,'sum'=>true),
			'extra_cost' => array('Q',12,'getExtraCostName','sum'=>true),
			'remark' => array('R',20)
		);
	}
	
	public function getLoadingStatusNames(){
		return $this->_loading_status;
	} 
	
	public function getLoadingStatusName($n=null){
		if(!isset($this->loading_status)) return '';
		return $this->_loading_status[$n==null?$this->loading_status:$n];
	}
	
	public function getReturnPaperNames(){
		return $this->_return_paper;
	}
	
	public function getReturnPaperName($n=null){
		if(!isset($this->return_paper)) return '';
		return $this->_return_paper[$n==null?$this->return_paper:$n];
	}
	
	public function getExtraCostName(){
		if(!isset($this->extra_cost)||$this->extra_cost=='') return '0.00';
		return $this->extra_cost;
	}
}